#! /bin/sh /usr/share/dpatch/dpatch-run
## 49_skiploop.dpatch by Jean-Yves Avenard <jean-yves@avenard.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@
diff -urNad mythtv-0.22.0-fixes22840~/libs/libmythtv/avformatdecoder.cpp mythtv-0.22.0-fixes22840/libs/libmythtv/avformatdecoder.cpp
--- mythtv-0.22.0-fixes22840~/libs/libmythtv/avformatdecoder.cpp	2009-11-17 01:37:36.000000000 +0100
+++ mythtv-0.22.0-fixes22840/libs/libmythtv/avformatdecoder.cpp	2009-11-17 01:37:40.000000000 +0100
@@ -1631,6 +1631,11 @@
                     vdp.SetInput(QSize(width, height));
                     dec = vdp.GetDecoder();
                     thread_count = vdp.GetMaxCPUs();
+                    bool skip_loop_filter = vdp.IsSkipLoopEnabled();
+                    if  (!skip_loop_filter)
+                    {
+                        enc->skip_loop_filter = AVDISCARD_NONKEY;
+                    }  
                 }
 
                 bool handled = false;
diff -urNad mythtv-0.22.0-fixes22840~/libs/libmythtv/videodisplayprofile.cpp mythtv-0.22.0-fixes22840/libs/libmythtv/videodisplayprofile.cpp
--- mythtv-0.22.0-fixes22840~/libs/libmythtv/videodisplayprofile.cpp	2009-11-17 01:37:36.000000000 +0100
+++ mythtv-0.22.0-fixes22840/libs/libmythtv/videodisplayprofile.cpp	2009-11-17 01:37:46.000000000 +0100
@@ -175,6 +175,7 @@
     QString cmp1      = Get("pref_cmp1");
     QString decoder   = Get("pref_decoder");
     uint    max_cpus  = Get("pref_max_cpus").toUInt();
+    bool    skiploop  = Get("pref_skiploop").toInt();
     QString renderer  = Get("pref_videorenderer");
     QString osd       = Get("pref_osdrenderer");
     QString deint0    = Get("pref_deint0");
@@ -182,9 +183,9 @@
     QString filter    = Get("pref_filters");
     bool    osdfade   = Get("pref_osdfade").toInt();
 
-    QString str =  QString("cmp(%1%2) dec(%3) cpus(%4) rend(%5) ")
+    QString str =  QString("cmp(%1%2) dec(%3) cpus(%4) skiploop(%5) rend(%6) ")
         .arg(cmp0).arg(QString(cmp1.isEmpty() ? "" : ",") + cmp1)
-        .arg(decoder).arg(max_cpus).arg(renderer);
+        .arg(decoder).arg(max_cpus).arg((skiploop) ? "enabled" : "disabled").arg(renderer);
     str += QString("osd(%1) osdfade(%2) deint(%3,%4) filt(%5)")
         .arg(osd).arg((osdfade) ? "enabled" : "disabled")
         .arg(deint0).arg(deint1).arg(filter);
@@ -858,7 +859,7 @@
     uint groupid, uint priority,
     QString cmp0, uint width0, uint height0,
     QString cmp1, uint width1, uint height1,
-    QString decoder, uint max_cpus, QString videorenderer,
+    QString decoder, uint max_cpus, bool skiploop, QString videorenderer,
     QString osdrenderer, bool osdfade,
     QString deint0, QString deint1, QString filters)
 {
@@ -904,6 +905,9 @@
     queryValue += "pref_max_cpus";
     queryData  += QString::number(max_cpus);
 
+    queryValue += "pref_skiploop";
+    queryData  += (skiploop) ? "1" : "0";
+
     queryValue += "pref_videorenderer";
     queryData  += videorenderer;
 
@@ -1017,48 +1021,48 @@
     DeleteProfileGroup("CPU++", hostname);
     uint groupid = CreateProfileGroup("CPU++", hostname);
     CreateProfile(groupid, 1, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", true,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", true,
                   "bobdeint", "linearblend", "");
     CreateProfile(groupid, 2, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "quartz-blit", "softblend", true,
+                  "ffmpeg", 1, true, "quartz-blit", "softblend", true,	     
                   "linearblend", "linearblend", "");
 
     (void) QObject::tr("CPU+", "Sample: Hardware assist HD only");
     DeleteProfileGroup("CPU+", hostname);
     groupid = CreateProfileGroup("CPU+", hostname);
     CreateProfile(groupid, 1, "<=", 720, 576, ">", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", true,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", true,
                   "bobdeint", "linearblend", "");
     CreateProfile(groupid, 2, "<=", 1280, 720, ">", 720, 576,
-                  "xvmc", 1, "xvmc-blit", "opengl", true,
+                  "xvmc", 1, true, "xvmc-blit", "opengl", true,
                   "bobdeint", "onefield", "");
     CreateProfile(groupid, 3, "<=", 1280, 720, ">", 720, 576,
-                  "libmpeg2", 1, "xv-blit", "softblend", true,
+                  "libmpeg2", 1, true, "xv-blit", "softblend", true,
                   "bobdeint", "onefield", "");
     CreateProfile(groupid, 4, ">", 0, 0, "", 0, 0,
-                  "xvmc", 1, "xvmc-blit", "ia44blend", false,
+                  "xvmc", 1, true, "xvmc-blit", "ia44blend", false,
                   "bobdeint", "onefield", "");
     CreateProfile(groupid, 5, ">", 0, 0, "", 0, 0,
-                  "libmpeg2", 1, "xv-blit", "chromakey", false,
+                  "libmpeg2", 1, true, "xv-blit", "chromakey", false,
                   "bobdeint", "onefield", "");
 
     (void) QObject::tr("CPU--", "Sample: Hardware assist all");
     DeleteProfileGroup("CPU--", hostname);
     groupid = CreateProfileGroup("CPU--", hostname);
     CreateProfile(groupid, 1, "<=", 720, 576, ">", 0, 0,
-                  "ivtv", 1, "ivtv", "ivtv", true,
+                  "ivtv", 1, true, "ivtv", "ivtv", true,
                   "none", "none", "");
     CreateProfile(groupid, 2, "<=", 720, 576, ">", 0, 0,
-                  "xvmc", 1, "xvmc-blit", "ia44blend", false,
+                  "xvmc", 1, true, "xvmc-blit", "ia44blend", false,
                   "bobdeint", "onefield", "");
     CreateProfile(groupid, 3, "<=", 1280, 720, ">", 720, 576,
-                  "xvmc", 1, "xvmc-blit", "ia44blend", false,
+                  "xvmc", 1, true, "xvmc-blit", "ia44blend", false,
                   "bobdeint", "onefield", "");
     CreateProfile(groupid, 4, ">", 0, 0, "", 0, 0,
-                  "xvmc", 1, "xvmc-blit", "ia44blend", false,
+                  "xvmc", 1, true, "xvmc-blit", "ia44blend", false,
                   "bobdeint", "onefield", "");
     CreateProfile(groupid, 5, ">", 0, 0, "", 0, 0,
-                  "libmpeg2", 1, "xv-blit", "chromakey", false,
+                  "libmpeg2", 1, true, "xv-blit", "chromakey", false,
                   "none", "none", "");
 }
 
@@ -1068,48 +1072,48 @@
     DeleteProfileGroup("High Quality", hostname);
     uint groupid = CreateProfileGroup("High Quality", hostname);
     CreateProfile(groupid, 1, ">=", 1920, 1080, "", 0, 0,
-                  "ffmpeg", 2, "xv-blit", "softblend", true,
+                  "ffmpeg", 2, true, "xv-blit", "softblend", true,
                   "linearblend", "linearblend", "");
     CreateProfile(groupid, 2, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", true,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", true,
                   "yadifdoubleprocessdeint", "yadifdeint", "");
     CreateProfile(groupid, 3, ">=", 1920, 1080, "", 0, 0,
-                  "ffmpeg", 2, "quartz-blit", "softblend", true,
+                  "ffmpeg", 2, true, "quartz-blit", "softblend", true,
                   "linearblend", "linearblend", "");
     CreateProfile(groupid, 4, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "quartz-blit", "softblend", true,
+                  "ffmpeg", 1, true, "quartz-blit", "softblend", true,
                   "yadifdoubleprocessdeint", "yadifdeint", "");
 
     (void) QObject::tr("Normal", "Sample: average quality");
     DeleteProfileGroup("Normal", hostname);
     groupid = CreateProfileGroup("Normal", hostname);
     CreateProfile(groupid, 1, ">=", 1280, 720, "", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", false,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", false,
                   "linearblend", "linearblend", "");
     CreateProfile(groupid, 2, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", true,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", true,
                   "greedyhdoubleprocessdeint", "kerneldeint", "");
     CreateProfile(groupid, 3, ">=", 1280, 720, "", 0, 0,
-                  "ffmpeg", 1, "quartz-blit", "softblend", false,
+                  "ffmpeg", 1, true, "quartz-blit", "softblend", false,
                   "linearblend", "linearblend", "");
     CreateProfile(groupid, 4, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "quartz-blit", "softblend", true,
+                  "ffmpeg", 1, true, "quartz-blit", "softblend", true,
                   "greedyhdoubleprocessdeint", "kerneldeint", "");
 
     (void) QObject::tr("Slim", "Sample: low CPU usage");
     DeleteProfileGroup("Slim", hostname);
     groupid = CreateProfileGroup("Slim", hostname);
     CreateProfile(groupid, 1, ">=", 1280, 720, "", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", false,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", false,
                   "onefield", "onefield", "");
     CreateProfile(groupid, 2, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "xv-blit", "softblend", true,
+                  "ffmpeg", 1, true, "xv-blit", "softblend", true,
                   "linearblend", "linearblend", "");
     CreateProfile(groupid, 3, ">=", 1280, 720, "", 0, 0,
-                  "ffmpeg", 1, "quartz-blit", "softblend", false,
+                  "ffmpeg", 1, true, "quartz-blit", "softblend", false,
                   "onefield", "onefield", "");
     CreateProfile(groupid, 4, ">", 0, 0, "", 0, 0,
-                  "ffmpeg", 1, "quartz-blit", "softblend", true,
+                  "ffmpeg", 1, true, "quartz-blit", "softblend", true,
                   "linearblend", "linearblend", "");
 }
 
@@ -1119,7 +1123,7 @@
     DeleteProfileGroup("VDPAU High Quality", hostname);
     uint groupid = CreateProfileGroup("VDPAU High Quality", hostname);
     CreateProfile(groupid, 1, ">", 0, 0, "", 0, 0,
-                  "vdpau", 1, "vdpau", "vdpau", true,
+                  "vdpau", 1, true, "vdpau", "vdpau", true,
                   "vdpauadvanceddoublerate", "vdpauadvanced",
                   "vdpaucolorspace=auto");
 
@@ -1127,11 +1131,11 @@
     DeleteProfileGroup("VDPAU Normal", hostname);
     groupid = CreateProfileGroup("VDPAU Normal", hostname);
     CreateProfile(groupid, 1, ">=", 0, 720, "", 0, 0,
-                  "vdpau", 1, "vdpau", "vdpau", true,
+                  "vdpau", 1, true, "vdpau", "vdpau", true,
                   "vdpaubasicdoublerate", "vdpaubasic",
                   "vdpaucolorspace=auto");
     CreateProfile(groupid, 2, ">", 0, 0, "", 0, 0,
-                  "vdpau", 1, "vdpau", "vdpau", true,
+                  "vdpau", 1, true, "vdpau", "vdpau", true,
                   "vdpauadvanceddoublerate", "vdpauadvanced",
                   "vdpaucolorspace=auto");
 
@@ -1139,7 +1143,7 @@
     DeleteProfileGroup("VDPAU Slim", hostname);
     groupid = CreateProfileGroup("VDPAU Slim", hostname);
     CreateProfile(groupid, 1, ">", 0, 0, "", 0, 0,
-                  "vdpau", 1, "vdpau", "vdpau", false,
+                  "vdpau", 1, true, "vdpau", "vdpau", false,
                   "vdpaubobdeint", "vdpauonefield", "vdpauskipchroma,vdpaucolorspace=auto");
 }
 
diff -urNad mythtv-0.22.0-fixes22840~/libs/libmythtv/videodisplayprofile.h mythtv-0.22.0-fixes22840/libs/libmythtv/videodisplayprofile.h
--- mythtv-0.22.0-fixes22840~/libs/libmythtv/videodisplayprofile.h	2009-11-07 12:40:31.000000000 +0100
+++ mythtv-0.22.0-fixes22840/libs/libmythtv/videodisplayprofile.h	2009-11-17 01:37:40.000000000 +0100
@@ -84,6 +84,9 @@
     uint GetMaxCPUs(void) const
         { return GetPreference("pref_max_cpus").toUInt(); }
 
+    bool IsSkipLoopEnabled(void) const
+        { return GetPreference("pref_skiploop").toInt(); }
+    
     QString GetVideoRenderer(void) const
         { return GetPreference("pref_videorenderer"); }
 
@@ -125,7 +128,7 @@
         uint grpid, uint priority,
         QString cmp0, uint width0, uint height0,
         QString cmp1, uint width1, uint height1,
-        QString decoder, uint max_cpus, QString videorenderer,
+        QString decoder, uint max_cpus, bool skiploop, QString videorenderer,
         QString osdrenderer, bool osdfade,
         QString deint0, QString deint1, QString filters);
 
diff -urNad mythtv-0.22.0-fixes22840~/programs/mythfrontend/globalsettings.cpp mythtv-0.22.0-fixes22840/programs/mythfrontend/globalsettings.cpp
--- mythtv-0.22.0-fixes22840~/programs/mythfrontend/globalsettings.cpp	2009-11-17 01:37:36.000000000 +0100
+++ mythtv-0.22.0-fixes22840/programs/mythfrontend/globalsettings.cpp	2009-11-17 01:37:46.000000000 +0100
@@ -873,6 +873,7 @@
     height[1] = new TransSpinBoxSetting(0, 1088, 64, true);
     decoder   = new TransComboBoxSetting();
     max_cpus  = new TransSpinBoxSetting(1, HAVE_THREADS ? 4 : 1, 1, true);
+    skiploop  = new TransCheckBoxSetting();
     vidrend   = new TransComboBoxSetting();
     osdrend   = new TransComboBoxSetting();
     osdfade   = new TransCheckBoxSetting();
@@ -904,6 +905,7 @@
 
     decoder->setLabel(tr("Decoder"));
     max_cpus->setLabel(tr("Max CPUs"));
+    skiploop->setLabel(tr("Loopfilter"));
     vidrend->setLabel(tr("Video Renderer"));
     osdrend->setLabel(tr("OSD Renderer"));
     osdfade->setLabel(tr("OSD Fade"));
@@ -921,6 +923,12 @@
     filters->setHelpText(
         QObject::tr("Example Custom filter list: 'ivtc,denoise3d'"));
 
+    skiploop->setHelpText(
+        tr("When unchecked the deblocking loopfilter will be disabled "
+           "for h264 decoding.") + "\n" +
+        tr("Disabling will significantly reduce the load on the CPU "
+           "when watching HD h264."));
+
     osdfade->setHelpText(
         tr("When unchecked the OSD will not fade away but instead "
            "will disappear abruptly.") + "\n" +
@@ -929,7 +937,7 @@
 
     vid_row->addChild(decoder);
     vid_row->addChild(max_cpus);
-
+    vid_row->addChild(skiploop);
     osd_row->addChild(vidrend);
     osd_row->addChild(osdrend);
     osd_row->addChild(osdfade);
@@ -982,6 +990,7 @@
 
     QString pdecoder  = item.Get("pref_decoder");
     QString pmax_cpus = item.Get("pref_max_cpus");
+    QString pskiploop  = item.Get("pref_skiploop");
     QString prenderer = item.Get("pref_videorenderer");
     QString posd      = item.Get("pref_osdrenderer");
     QString posdfade  = item.Get("pref_osdfade");
@@ -1009,6 +1018,9 @@
 
     if (!pmax_cpus.isEmpty())
         max_cpus->setValue(pmax_cpus.toUInt());
+
+    skiploop->setValue((!pskiploop.isEmpty()) ? (bool) pskiploop.toInt() : true);
+
     if (!prenderer.isEmpty())
         vidrend->setValue(prenderer);
     if (!posd.isEmpty())
@@ -1042,6 +1054,7 @@
 
     item.Set("pref_decoder",       decoder->getValue());
     item.Set("pref_max_cpus",      max_cpus->getValue());
+    item.Set("pref_skiploop",       (skiploop->boolValue()) ? "1" : "0");
     item.Set("pref_videorenderer", vidrend->getValue());
     item.Set("pref_osdrenderer",   osdrend->getValue());
     item.Set("pref_osdfade",       (osdfade->boolValue()) ? "1" : "0");
diff -urNad mythtv-0.22.0-fixes22840~/programs/mythfrontend/globalsettings.h mythtv-0.22.0-fixes22840/programs/mythfrontend/globalsettings.h
--- mythtv-0.22.0-fixes22840~/programs/mythfrontend/globalsettings.h	2009-10-15 03:32:30.000000000 +0200
+++ mythtv-0.22.0-fixes22840/programs/mythfrontend/globalsettings.h	2009-11-17 01:37:46.000000000 +0100
@@ -87,6 +87,7 @@
     TransSpinBoxSetting  *height[2];
     TransComboBoxSetting *decoder;
     TransSpinBoxSetting  *max_cpus;
+    TransCheckBoxSetting *skiploop;
     TransComboBoxSetting *vidrend;
     TransComboBoxSetting *osdrend;
     TransCheckBoxSetting *osdfade;
